<?php

namespace App\Notifications\Wechat;

use App\Internals\UserInternal;

class OrderSuccess extends Notification
{
    public function notify($userId, $paidAmount, $courseName, $tradeNo, $courseLevels)
    {
        $templateId = 'sT5h_B-AwlEJZjGhSwFjIYo35m5tkIf5msU35fKvC6I';
        $socialAccount = UserInternal::getSocialAccount($userId);
        $url = config('app.base_url') . '/?#/user/order';

        $tmp = [];
        foreach($courseLevels as $level) {
            $tmp[] = 'Level ' . $level . '课程';
        }
        $nameArr = explode('-', $courseName);
        $courseName =  trim($nameArr[1]) . ' - ' . implode('、', $tmp);

        $data = [
            'first'    => sprintf("%s 家长您好，你已成功购买课程！\n", $socialAccount['nickname']),
            'keyword1' => ['￥' . $paidAmount, '#FF6F6F'],
            'keyword2' => [$courseName, '#FF6F6F'],
            'keyword3' => [$tradeNo."\n", '#FF6F6F'],
            'remark'   => ['点击下方查看详情！', '#FF6F6F'],
        ];
        $this->send($socialAccount['openId'], $templateId, $url, $data);
    }
}
